package anthology.daily_question._24_12;

import java.util.ArrayList;
import java.util.List;

//https://leetcode.cn/problems/find-occurrences-of-an-element-in-an-array/description/?envType=daily-question&envId=2024-12-27
public class _3159查询数组中元素的出现位置 {
    class Solution {
        public int[] occurrencesOfElement(int[] nums, int[] queries, int x) {
            List<Integer> indices = new ArrayList<>();
            for (int i = 0; i < nums.length; i++) {
                if (nums[i] == x) {
                    indices.add(i);
                }
            }

            int[] res = new int[queries.length];
            for (int i = 0; i < queries.length; i++) {
                if (indices.size() < queries[i]) {
                    res[i] = -1;
                } else {
                    res[i] = indices.get(queries[i] - 1);
                }
            }
            return res;
        }
    }
}
